<template>
  <view>
    <text v-if="hasPromission" class="order_no" @click.stop="toPage()">{{ orderCode || '-' }}</text>
    <text v-else selectable="true" user-select="true">{{ orderCode || '-' }}</text>
    <text v-if="appendText">{{ appendText }}</text>
    <text>&nbsp;</text>
    <ve-tag v-if="tagText" color="red" :title="tagText"></ve-tag>
  </view>
</template>

<script setup>
  // 跳转链接组件，有权限展示位link，没有权限展示为文本
  import { usePermission } from '@/hooks/usePermission'

  // 权限枚举
  // 2: 短租,3: 普通长租,4: 车辆维修,5: 车辆保养,6: 车辆年检,11:临时占用,12:借出
  const REDIRECT_ENUM = {
    2: { label: '短租详情', permission: 'svmsapp:order:short-order.view', path: '/pages/order/short-order/detail/index' },
    3: { label: '长租详情', permission: 'svmsapp:order:long-order.view', path: '/pages/order/long-order/detail/index' },
    4: { label: '维修详情', permission: 'svmsapp:car-repair.detail', path: '/pages/asset/car-repair/detail/index' },
    5: { label: '保养详情', permission: 'svmsapp:car-maintenance.detail', path: '/pages/asset/car-maintenance/detail' },
    6: { label: '年检详情', permission: 'svmsapp:car-inspect.detail', path: '/pages/asset/car-inspect/detail' },
    // 此组件给排车图优先使用，后面的link从101开始
    // 101: { label: '调拨', value: 'svms:order:transfer' },
  }

  const props = defineProps({
    id: Number,
    orderCode: String,
    // 没有type 按普通文本处理
    type: Number,
    append: String,
    tag: String,
    disabled: Boolean,
  })

  // 获取权限
  const getPromission = (page) => {
    if (props.disabled) return false
    if (!page || !page.permission) {
      return false
    }
    return usePermission(page.permission)
  }

  const appendText = props.type && props.append ? `(${props.append})` : ''
  const tagText = props.type && props.tag ? props.tag : ''
  const page = REDIRECT_ENUM[props.type]
  const hasPromission = getPromission(page)
  const toPage = () => {
    uni.navigateTo({
      url: page.path + '?id=' + props.id,
    })
  }
</script>

<style lang="less" scoped>
  .order_no {
    display: flex;
    align-items: center;
    color: #3072f6;
    font-weight: 400;
    font-size: 28rpx;
  }
</style>
